<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
	
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Iterator" %>

<%@ page import ="com.easyattendance.services.AddTeacherService" %>
<%@ page import ="com.easyattendance.model.Teacher" %>
<%@ page import ="com.easyattendance.services.AddStudentService" %>
<%@ page import ="com.easyattendance.model.Student" %>
<%@ page import ="com.easyattendance.services.AddClassService" %>
<%@ page import ="com.easyattendance.model.Class" %>
<%@ page import ="com.easyattendance.services.AddTeacherService" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Teacher - Student Settings</title>
<!-- <script src="http://code.jquery.com/jquery-1.11.0.min.js"></script> -->
<jsp:include page="../includeFiles.jsp" />


<!-- fooTable Links -->
<link href="../css/footable.core.css" rel="stylesheet" type="text/css" />
<link href="../css/footable.metro.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/public/js/footable.js" type="text/javascript"></script>
<script src="<%=request.getContextPath()%>/public/js/footable.sort.js" type="text/javascript"></script>

<link rel="stylesheet" href="<%=request.getContextPath()%>/views/css/ui/jquery-ui-1.10.4.custom.min.css">
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.core.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.widget.js"></script>
<script src="<%=request.getContextPath()%>/public/js/ui/jquery.ui.datepicker.js"></script>

<script type="text/javascript">
	$(function () {
		$('.footable').footable();
	});
</script>

<script>
	$(function() {
		$( "#stud_dob" ).datepicker({
			beforeShowDay: noSunday,
			dateFormat: 'yy-mm-dd'
		});
	});
	function noSunday(date){ 
	     return [date.getDay() != 0, ''];
	};
</script>

</head>

<body class="left-sidebar">

<!-- Session check : user logged in or not/ press back button -->
<jsp:include page="../common/checkSession.jsp" />
<jsp:include page="../common/checkTeacherRole.jsp" />

<% String currentUser = (String) session.getAttribute("currentUser");
	AddTeacherService addTeacherService = new AddTeacherService();
	Teacher teacher_role = addTeacherService.getTeacherByEmailId(currentUser);
%>

	
	<!-- Wrapper -->
	<div id="wrapper">

		<!-- Content -->
		<div id="content">
			<div id="content-inner">

				<%-- <% if (addTeacherService.ifClassTeacher(currentUser)) { %> --%>
				<div>
					<!-- ONLY VISIBLE TO CLASS TEACHER ONLY -->
					<form action="<%=request.getContextPath()%>/views/teacher/addStudent.jsp">
						<input type="submit" value="Add Student" class="button add_button" tabindex="1">
					</form>
				</div>
				<%-- <% } %> --%>
				
				<div>
				<span class="success_msg">${dataImported}</span>
				<span class="error_msg">${dataNotImported}</span>
					<!-- ONLY VISIBLE TO CLASS TEACHER ONLY -->
					<form action="${pageContext.request.contextPath}/ReadStudentExcel">
						<input type="submit" value="Import Student List" class="button add_button" tabindex="2">
					</form>
				
				
				<span class="success_msg">${studentParentUpdated}</span>
				<span class="error_msg">${studentParentNotUpdated}</span>
				<span class="success_msg">${studentDeleted}</span>
				<span class="error_msg">${studentNotDeleted}</span>
				<span class="error_msg">${invalidChoice}</span>
				
				
					<% AddClassService addClassService = new AddClassService();
						String ClassId =addClassService.getClassIdByTeacherId(currentUser); %>
					<%	 
						String deptId = addTeacherService.getSectionIdByTeacherId(currentUser);%>
				
					<% AddStudentService addStudentService = new AddStudentService();	
					List<Student> studentList = null;
					studentList = addStudentService.getStudentList(deptId, ClassId);
					Student tempStudent = null;
				
					Iterator studentItr = studentList.iterator();
					int i=0; %>
					<table name="studentList" id="studentList" class="footable metro-attendance">
						<thead>
			                <tr>
			                    <th data-toggle="true" data-sort-ignore="true" data-hide="phone,tablet"></th>
			                    
			                    <th data-toggle="true" data-sort-initial="true">
			                        First Name
			                    </th>
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Last Name
			                    </th>
			                    <th data-toggle="true" data-sort-initial="true">
			                        Roll No
			                    </th>  
			                    <th data-toggle="true" data-sort-ignore="true">
			                        Email ID
			                    </th>
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Address
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true">
			                        Contact (M)
			                    </th>
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Contact (R)
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true" data-hide="phone,tablet">
			                        Date Of Birth
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true" data-hide="phone,tablet">
			                        Gender
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true">
			                        Parent Contact (M)
			                    </th>
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Parent Contact (O)
			                    </th>
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Parent Email
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true" data-hide="phone,tablet">
			                        Parent Gender
			                    </th>			                    
			                    <th data-sort-ignore="true" data-hide="phone,tablet">
			                        Save
			                    </th>
			                    <th data-toggle="true" data-sort-ignore="true" data-hide="phone,tablet">
			                        Delete
			                    </th>
			                </tr>
		                </thead>
		                <tbody>
							<% while(studentItr.hasNext()) { i++;%>
								
							<% try	{
										tempStudent = (Student) studentItr.next();
									} 
									catch(Exception ex){
										ex.printStackTrace();
									}%> 							
							<tr>
								<form name="studentUpdateForm<%=i%>" action="${pageContext.request.contextPath}/AddStudentServlet" action="post">								
							
									<td data-value="<%= tempStudent.getStud_fname() %>">
										<input type="text" name="stud_fname<%=i%>" id="stud_fname<%=i%>" value="<%= tempStudent.getStud_fname() %>" >
									</td>									
									<td>
										<input type="text" name="stud_lname<%=i%>" id="stud_lname<%=i%>" value="<%= tempStudent.getStud_lname() %>" >
									</td>									
									<td data-value="<%= tempStudent.getStud_roll_no() %>">
										<input type="text" name="stud_roll_no<%=i%>" id="stud_roll_no<%=i%>" value="<%= tempStudent.getStud_roll_no() %>" >
									</td>
									<td>
										<input type="text" name="stud_email_id<%=i%>" id="stud_email_id<%=i%>" value="<%= tempStudent.getStud_email_id() %>" >
									</td>
									 <td>
										<input type="text" name="stud_address<%=i%>" id="stud_address<%=i%>" value="<%= tempStudent.getStud_address() %>" >
									</td> 
									<td>
										<input type="text" name="stud_mobile_no<%=i%>" id="stud_mobile_no<%=i%>" value="<%= tempStudent.getStud_mobile_no() %>" >
									</td>
									<td>
										<input type="text" name="stud_home_no<%=i%>" id="stud_home_no<%=i%>" value="<%= tempStudent.getStud_home_no() %>" >
									</td>
									<td>
										<input type="text" name="stud_dob<%=i%>" id="stud_dob<%=i%>" value="<%= tempStudent.getStud_dob() %>" placeholder="Date">
									</td>
									<td>
										<select name="gender_select<%=i%>" id="gender_select<%=i%>" value="<%=tempStudent.getStud_gender()%>">
											<option name="Male" value="Male">Male
											<option name="Female" value="Female">Female
										</select>
									</td>
									<td>
										<input type="text" name="parent_mobile_no<%=i%>" id="parent_mobile_no<%=i%>" value="<%= tempStudent.getParent().getParent_mobile_no() %>" >
									</td>
									<td>
										<input type="text" name="parent_office_no<%=i%>" id="parent_office_no<%=i%>" value="<%= tempStudent.getParent().getParent_office_no() %>" >
									</td>
									<td>
										<input type="text" name="parent_email<%=i%>" id="parent_email<%=i%>" value="<%= tempStudent.getParent().getParent_email_id() %>" >
									</td>
									<td>
										<select name="parent_gender_select<%=i%>" id="parent_gender_select<%=i%>" value="<%=tempStudent.getParent().getGender()%>">
											<option name="Male" value="Male">Male
											<option name="Female" value="Female">Female
										</select>
									</td>								
									<td>
										<input type="submit" value="" class="button save_button" style="clear: both;padding: 0.5em;">										
									</td>
								</form>
									
								<!-- </form> -->
									<td>
										<form name="studentDeleteForm<%=i%>" action="${pageContext.request.contextPath}/AddStudentServlet" action="post">
												<input type="submit" value="" class="delete_button" alt="Delete" onclick="return confirm('Are you sure you want to delete?')" style="padding: 1em 0.5em;background: url('../css/images/delete.png') no-repeat left;">
												<input type="hidden" id="action_type" name="action_type" value="delete">
												<input type="hidden" id="i_value" name="i_value" value=<%=i%>>
												<input type="hidden" id="stud_id<%=i%>" name="stud_id<%=i%>" value="<%= tempStudent.getStud_id() %>" >
										</form>
									</td>
						</tr>	
					<% } %>
					</tbody>
					</table>
				</div>
				
			</div>
		</div>

		<!-- Sidebar -->
		<div id="sidebar">

			<!-- Sidebar Header - Logo & Name -->
			<jsp:include page="../common/sidebarHeader.jsp" />

			<jsp:include page="teacherMenu.jsp" />

			<!-- Sidebar Footer Content -->
			<jsp:include page="../common/sidebarFooter.jsp" />

		</div>

	</div>	
	<script type="text/javascript">
		$(function(){
			$("#studentSettings").addClass("current_page_item");
		});
	</script>

</body>
</html>